/*
 * Created by Christopher King
 * Copyright (C) 2007 Christopher King, All Rights Reserved.
 */

package us.cirion.adventure.engine;

import java.util.Enumeration;
import java.util.Hashtable;

/**
 * A Room describes a physical location within the game world. It may be a
 * physical room, such as a kitchen or a dungeon, but it may also describe any
 * physical space, such as a forest or a highway. The player explores the game
 * world by moving through a sequence of rooms, each of which may contain items
 * with which to interact.
 * 
 * @author Chris
 */
public class Room extends ItemLocation
{

	String name;
	String description;
	Hashtable exits;

	/**
	 * Constructs a new Room instance with no exits or items.
	 */
	public Room()
	{
		super();
		exits = new Hashtable();
	}

	/**
	 * Provides a human-readable description of the room.
	 * 
	 * @return A string describing the room.
	 */
	public String getDescription()
	{
		return description;
	}

	/**
	 * Assign the human-readable description of the room. This should be a
	 * complete sentence that will inform the player of their location.
	 * 
	 * @param description The string describing the room.
	 */
	public void setDescription(String description)
	{
		this.description = description;
	}

	/**
	 * Retrieves the program-readable name of the room. This can be used to
	 * uniquely assign actions or items associated with the room.
	 * 
	 * @return The name of the room.
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Assign the unique, program-readable name of the room. Note that while
	 * multiple rooms may have the same description, such as "You are in a
	 * forest.", each room must have a unique name, such as "forest1",
	 * "forest2", etc.
	 * 
	 * @param name The name of the room.
	 */
	public void setName(String name)
	{
		this.name = name;
	}

	/**
	 * Retrieves the name of the room that lies in the indicated direction.
	 * 
	 * @param direction The direction from which to obtain the next room.
	 * @return String describing the name of the next room, or <code>null</code>
	 *         if there is no room in that direction.
	 */
	public String getExit(Direction direction)
	{
		return (String) exits.get(direction);
	}

	/**
	 * Retrieves the valid, visible exit directions from this room. Each exit
	 * will lead to another Room.
	 * 
	 * @return An Enumeration of Directions that lead from this room.
	 */
	public Enumeration getExitDirections()
	{
		return exits.keys();
	}

	/**
	 * Describe a connection between this room and another.
	 * 
	 * @param direction The direction in which the next room lies.
	 * @param destination The name of the next room.
	 */
	public void addExit(Direction direction, String destination)
	{
		exits.put(direction, destination);
	}

	/**
	 * Determines whether this Room is the same as another.
	 * 
	 * @return <code>true</code> if the provided object is a Room with the
	 *         same name, <code>false</code> otherwise.
	 */
	public boolean equals(Object o)
	{
		if (o == this)
		{
			return true;
		}
		if (!(o instanceof Room))
		{
			return false;
		}
		return ((Room) o).getName().equals(getName());
	}

	public String toString()
	{
		return name;
	}

}
